package com.zzl.controller;

import com.zzl.entiey.PsGoods;
import com.zzl.service.GoodsService;
import com.zzl.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: GoodsController
 * @Description: GOOD
 * @author: ZZL
 * @date: 2021/7/7  14:14
 */
@RestController
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("/goods/findAll")
    public Result findAllGoods(@RequestParam String goodsType){
        List<PsGoods> goods = goodsService.findAllGoodsByType(goodsType);
        return Result.succ(goods);
    }

    @GetMapping("/goods/findByName")
    public Result findGoodsByName(@RequestParam String goodsName){
        PsGoods goodsByName = goodsService.findGoodsByName(goodsName);
        return Result.succ(goodsByName);
    }

    @RequestMapping("/goods/findGoodsNumber")
    public Result findGoodsNumber(@RequestParam String goodsName){
        int goodsNum = goodsService.findGoodsNumber(goodsName);
        return Result.succ(goodsNum);
    }

    @RequestMapping("/goods/findAllGoodsList")
    public Result findGoodsNumber(){
        return Result.succ(goodsService.findAllGoods());
    }

    @RequestMapping("/goods/editGoods")
    public Result editGoods(@RequestBody PsGoods psGoods){
        goodsService.editGoods(psGoods);
        return Result.succ("修改成功");
    }

    @RequestMapping("/goods/deletedGoods")
    public Result deletedGoods(@RequestParam String goodsName){
        goodsService.deletedGoodsByGoodsName(goodsName);
        return Result.succ("删除成功");
    }

    @RequestMapping("/goods/insertGoods")
    public Result insertGoods(@RequestBody PsGoods psGoods){
        goodsService.insertGoods(psGoods);
        return Result.succ("添加成功");
    }
}
